package oboe.controllers.jml.helpers;

import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.ui.Keyboard;

import oboe.controllers.jml.JMLController;

class JMLInput extends JMLNode
{
public function new(head:String, jml:Object, parent:JMLController)
{
	super(head, jml, parent);
}

protected override function createDisplayObject(type:String):DisplayObject
{
	var tf:TextField;
	tf = new TextField();
	tf.type = TextFieldType.INPUT;
	tf.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
	return tf;
}

private function onKeyDown( e:KeyboardEvent ):Void
{
	if( e.keyCode == Keyboard.ENTER )
	{
	this.getDisplayObject().dispatchEvent( new Event("enter") );
	}
}

public function slot_onPollFormInputs( val:Object ):Void
{
	var text:TextField = this.getDisplayObject() as TextField;
	val[ text.name ] = text.text; 
}
}